package com.sebiotec.glp.limoapp.service;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;

import androidx.core.app.NotificationCompat;

import com.bill.module_notification.ChannelEntity;
import com.bill.module_notification.ImportanceType;
import com.bill.module_notification.NotifyManager;


import com.sebiotec.glp.limoapp.MainActivity;
import com.sebiotec.glp.limoapp.R;

public class Text1 {

    private static NotifyManager notifyManager;
    private static String GROUP_KEY_WORK_EMAIL = "com.android.example.WORK_EMAIL";
    public static void dd(Context context){
        initNocation(context);

        if (!notifyManager.areNotificationsEnabled()) {

            return;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (!notifyManager.areChannelsEnabled(Constants.CHANNEL_CHAT)) {

                return;
            }
        }

        Intent mainIntent = new Intent(context, MainActivity.class);

        Bundle bundle = new Bundle();
        bundle.putSerializable("tz", "tz");
        mainIntent.putExtras(bundle);

        PendingIntent mainPendingIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//        Notification notification = new NotificationCompat.Builder(context, com.czy.sjm.model.Constants.CHANNEL_CHAT)
//                .setContentTitle("New Messages")
//                .setContentText("You've received 3 new messages.")
//                .setSmallIcon(R.drawable.ic_stat_ic_notification)
//                .setNumber(1)
//                .setContentIntent(mainPendingIntent)
//                .build();


        String GROUP_KEY_WORK_EMAIL = "com.android.example.WORK_EMAIL";
//
//        Notification newMessageNotification = new NotificationCompat.Builder(context, com.czy.sjm.model.Constants.CHANNEL_CHAT)
//                .setSmallIcon(R.drawable.ic_stat_name)
//                .setContentTitle("1")
//                .setContentText("2")
//
//                .setGroup(GROUP_KEY_WORK_EMAIL)
//                  .setGroupSummary(true)
//                .build();
        NotificationCompat.Builder builder = notifyManager.getDefaultBuilder(Constants.GROUP_CHAT);
        builder.setContentTitle("1");
        builder.setContentText("2");
        builder.setSmallIcon(R.drawable.ic_stat_name);
        builder.setNumber(1);
        builder.setColor(Color.parseColor("#D9BE83"));
        builder.setAutoCancel(true);
        builder.setContentIntent(mainPendingIntent);
        builder.setGroup(GROUP_KEY_WORK_EMAIL);
        builder.setGroupSummary(true);
        Notification newMessageNotification = builder.build();

        notifyManager.notifyNotify(newMessageNotification);

        //更新角标
        try {
            BadgeUtil.setBadgeCount(context , 2 , newMessageNotification);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private static void initNocation(Context context) {
        notifyManager = new NotifyManager(context);

        ChannelEntity chatChannel = new ChannelEntity(Constants.GROUP_CHAT, "新聊天消息", ImportanceType.IMPORTANCE_HIGH);
        chatChannel.setDescription("个人或群组发来的聊天消息");
        chatChannel.setShowBadge(true);
        notifyManager.createNotificationChannel( chatChannel);

    }

}
